package com.chen.controller;


import com.chen.entity.CartItem;
import com.chen.service.CartItemService;
import com.chen.vo.Result;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 购物车表 前端控制器
 * </p>
 *
 * @author cws
 * @since 2024-11-26
 */
@RestController
@RequestMapping("/mall/cartItem")
public class CartItemController {

    @Resource
    private CartItemService cartItemService;


    @ApiModelProperty("添加至购物车")
    @PostMapping("/addCart")
    public Result addCart(@RequestBody CartItem cartItem){
        return cartItemService.addCart(cartItem);
    }

    @ApiModelProperty("数量加一")
    @PutMapping("/addOne/{id}")
    public Result addOne(@PathVariable("id") Long id){
        return cartItemService.addOne(id);
    }


    @ApiModelProperty("数量减一")
    @PutMapping("/minusOne/{id}")
    public Result minusOne(@PathVariable("id") Long id){
        return cartItemService.minusOne(id);
    }

    @ApiModelProperty("根据用户id查询购物车")
    @GetMapping("/list")
    public Result ByUserOfCartList(){
        return cartItemService.ByUserOfCartList();
    }

    @ApiModelProperty("根据购物车id批量删除购物车")
    @DeleteMapping("/delete")
    public Result deleteCartItemByIds(@RequestParam("ids") List<Long> ids){
        return cartItemService.deleteCartItemByIds(ids);
    }


    @ApiModelProperty("更具商品Id查询购物清单")
    @GetMapping("/getCartProduct")
    public Result getCartProduct(@RequestParam("ids") List<Long> ids){
        return Result.success(cartItemService.getCartProduct(ids));
    }


}

